﻿// This source is subject to Microsoft Public License (Ms-PL).
// Please see http://taskcardcreator.codeplex.com for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows.Documents;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using ReportingFramework;
using WorkItemReportInterface;

namespace MicrosoftVisualStudioScrum10Detailed
{
    /// <summary>
    /// Interaction logic for MicrosoftVisualStudioScrum10DetailedTemplate.xaml
    /// </summary>
    [Export(typeof(IWorkItemReport))]
    public partial class MicrosoftVisualStudioScrum10DetailedTemplate : Report, IWorkItemReport
    {
        public MicrosoftVisualStudioScrum10DetailedTemplate()
        {
            InitializeComponent();
        }
        public ReportType ProcessTemplate
        {
            get { return ReportType.MicrosoftVisualStudioScrum10; }
        }

        public string Description
        {
            get { return "Microsoft Visual Studio Scrum 1.0 Detailed Report"; }
        }

        public FixedDocument Create(IEnumerable<WorkItem> data)
        {
            var rows = new List<object>();
            foreach (var workItem in data)
            {
                switch (workItem.Type.Name)
                {
                    case "Product Backlog Item":
                        rows.Add(new ProductBacklogItemCardRow(workItem));
                        break;
                    case "Task":
                        rows.Add(new TaskCardRow(workItem));
                        break;
                    case "Bug":
                        rows.Add(new BugCardRow(workItem));
                        break;
                    case "Impediment":
                        rows.Add(new ImpedimentCardRow(workItem));
                        break;
                    case "Test Case":
                        rows.Add(new TestCaseCardRow(workItem));
                        break;
                    case "Shared Steps":
                        rows.Add(new SharedStepsCardRow(workItem));
                        break;
                    case "Sprint":
                        rows.Add(new SprintCardRow(workItem));
                        break;
                    default:
                        rows.Add(new UnknownCardRow(workItem));
                        break;
                }
            }

            return GenerateReport(
                page => new PageInfo(page, DateTime.Now),
                rows
                );
        }

        /// <summary>
        /// This class becomes the data context for every page. It gives the page 
        /// access to the page number.
        /// </summary>
        public class PageInfo
        {
            public PageInfo(int pageNumber, DateTime reportDate)
            {
                PageNumber = pageNumber;
                ReportDate = reportDate;
            }

            public bool IsFirstPage { get { return PageNumber == 1; } }
            public int PageNumber { get; set; }
            public DateTime ReportDate { get; set; }
        }
    }
}